{% extends 'base.html' %}
{% block title %}首页{% endblock %}
{% block content %}

    <main class="container bg-white p-3 rounded mt-3">
        <h2>文章列表</h2>
        <div class="row row-cols-1 row-cols-md-3 g-4 p-2">
            {% for blog in blogs %}
                <div class="col">
                    <div class="card h-100 shadow rounded bg-body-light">
                        
                        <div class="card-body d-flex flex-column">
                            <!-- 标题 -->
                            <h5 class="card-title">
                                <a href="{% url 'blog:detail' blog.id %}" class="notranslate immersive-translate-target-wrapper link-offset-2 link-underline
                                    link-underline-opacity-0">
                                    {{ blog.title }}
                                </a>
                            </h5>

                            <!-- 内容摘要：固定高度 + 截断 -->
                            <p class="card-text text-muted flex-grow-1" style="max-height: 80px; overflow: hidden;">
                                {{ blog.content|striptags|truncatechars:100 }}
                            </p>

                            <!-- 底部信息 -->
                            <div class="card-footer bg-transparent border-0 d-flex justify-content-between align-items-center pt-3 mt-auto">
                                <div class="d-flex align-items-center">
                                    <img src="{% static 'images/avatar.jpg' %}" alt="作者头像"
                                         class="rounded-circle me-2" width="30" height="30">
                                    <small>{{ blog.author.username }}</small>
                                </div>
                                <small class="text-muted">{{ blog.created_at|date:'Y-m-d' }}</small>
                            </div>
                        </div>
                    </div>
                </div>
            {% empty %}
                <div class="col-12">
                    <p class="text-center text-muted">暂无文章</p>
                </div>
            {% endfor %}
        </div>
    </main>


{% endblock %}